﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace App20._5
{
    /// <summary>
    /// Window6.xaml 的交互逻辑
    /// </summary>
    public partial class Window6 : Window
    {
        private bool _dragging = false;

        public Window6()
        {
            InitializeComponent();
        }

        private void BouncingBall_MouseMove(object sender, MouseEventArgs e)
        {
            _dragging = true;
        }

        private void BouncingBall_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (!_dragging)
            {
                return;
            }

            double x = Mouse.GetPosition(this.BouncingBallContainter).X;
            Vector vector = VisualTreeHelper.GetOffset(this.BouncingBall);
            double pX = vector.X;

            TranslateTransform t = (TranslateTransform)this.bounce;
            t.X = x - pX;
        }

        private void BouncingBall_MouseUp(object sender, MouseButtonEventArgs e)
        {
            _dragging = false;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }
    }

    public class FlipConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ((double)value * -1);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ((double)value * -1);
        }
    }
}
